AC_PREREQ(2.54)
AC_INIT(src/controller.h)

AM_SANITY_CHECK
AM_INIT_AUTOMAKE(tbcontroller, 0.1)
AM_CONFIG_HEADER(config.h)
AM_MAINTAINER_MODE
AC_PROG_CC
AC_ISC_POSIX
AC_PROG_LIBTOOL
AC_PROG_INSTALL
AM_PROG_CC_STDC
AC_HEADER_STDC

# GLIB
PKG_CHECK_MODULES(glib, [ 
  glib-2.0 >= 2.8.0
  gmodule-2.0 >= 2.8.0
  gthread-2.0 >= 2.8.0
])

LIBS="$LIBS $glib_LIBS"
CFLAGS="$CFLAGS $glib_CFLAGS -DG_DISABLE_DEPRECATED"

# NXML 
PKG_CHECK_MODULES(nxml, [ nxml >= 0.18.0 ])
LIBS="$LIBS $nxml_LIBS"
CFLAGS="$CFLAGS $nxml_CFLAGS"

# TbCommon
PKG_CHECK_MODULES(tbcommon, [ tbcommon >= 0.1.0 ])
LIBS="$LIBS $tbcommon_LIBS"
CFLAGS="$CFLAGS $tbcommon_CFLAGS"

AC_ARG_ENABLE(log2html, AC_HELP_STRING([--enable-log2html], [enable the log viewer (default=auto)]), log2html=$enableval, log2html=auto)

if test "$log2html" = yes ||
   test "$log2html" = auto; then

  # Graphviz
  AC_PATH_PROG(dot, dot)
  if test "$dot" = ""; then
    if test "$log2html" = yes; then
      AC_MSG_ERROR(No dot (graphviz) found!)
    else
      log2html="no"
    fi

  else
    # tbJson
    PKG_CHECK_MODULES(tbjson, [ tbjson >= 0.1.0 ], tbjson=yes, tbjson=no)

    if test "$tbjson" = no; then
      if test "$log2html" = yes; then
        AC_MSG_ERROR(tbjson not found!)
      else
        log2html="no"
      fi
    else
      LIBS="$LIBS $tbjson_LIBS"
      CFLAGS="$CFLAGS $tbjson_CFLAGS"
    fi
  fi
fi

AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [enable the debug functions (default=no)]), debug=$enableval, debug=no)

if test "$debug" != no; then
  if test "$debug" -ge 1 2>/dev/null; then
    CFLAGS="$CFLAGS -DTB_DEBUG=$debug"
  else
    CFLAGS="$CFLAGS -DTB_DEBUG=1"
  fi
fi

AM_CONDITIONAL(ENABLE_LOG2HTML, test "$log2html" != "no")

# Standard flags
CFLAGS="$CFLAGS -Wall"

AC_OUTPUT([
Makefile
src/Makefile
log2html/Makefile
log2html/data/Makefile
])

